# -*- coding:utf-8 -*-
from urllib.request import urlopen      #url操作
from json import load                   #json解析
import myconfig                         #配置类


def get_ip(url_api):
    my_ip = urlopen(url_api).read()        #获取IP
    #print('ip:', my_ip)
    ip_addr = my_ip.decode('utf-8')        #去除b`前缀
    #print(ip_addr)   
    return ip_addr 

try:
    ip = get_ip(myconfig.url1)  
except:
    try:
        print('url1 get ip error:404')
        ip = get_ip(myconfig.url2)
    except:
        print('url2 get ip error:404')
    else:
        print('get ip successfully')
else:        
    print('get ip successfully')

#print(ip)


